import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class RegisterPage extends StatefulWidget {
  const RegisterPage({super.key});

  @override
  State<RegisterPage> createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {
  TextEditingController? _nameController;
  FocusNode? _nameFocusNode;

  TextEditingController? _passController;
  FocusNode? _passFocusNode;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _nameController = TextEditingController();
    _nameFocusNode = FocusNode();
    _passController = TextEditingController();
    _passFocusNode = FocusNode();
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Material(
      child: Expanded(
        child: Container(
          color: Colors.teal,
          padding: EdgeInsets.only(left: 10.r, right: 10.r),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              inputWidget(_nameController!, _nameFocusNode!, "请输入账户"),
              SizedBox(
                height: 10.h,
              ),
              inputWidget(_passController!, _passFocusNode!, "请输入密码",
                  obscureText: true),
              SizedBox(
                height: 30.h,
              ),
              Container(
                width: 200.w,
                padding: EdgeInsets.all(20.r),
                decoration: BoxDecoration(
                    border: Border.all(width: 1.sp, color: Colors.white),
                    borderRadius: BorderRadius.all(Radius.circular(10.r))),
                child: Text(
                  "开始登录",
                  style: TextStyle(color: Colors.white, fontSize: 14.sp),
                  textAlign: TextAlign.center,
                ),
              ),
            ],
          ),
        ),
      ),
    ));
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _nameController?.dispose();
    _nameController = null;
    _passController?.dispose();
    _passController = null;
    _nameFocusNode?.dispose();
    _nameFocusNode = null;
    _passFocusNode?.dispose();
    _passFocusNode = null;

    super.dispose();
  }
}

Widget inputWidget(
    TextEditingController controller, FocusNode focusNode, String? labText,
    {bool? obscureText}) {
  return TextField(
    style: TextStyle(color: Colors.white),
    obscureText: true,
    controller: controller,
    focusNode: focusNode,
    decoration: InputDecoration(
        labelStyle: TextStyle(color: Colors.white),
        labelText: labText ?? "请输入",
        enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: Colors.white, width: 0.5.r),
            borderRadius: BorderRadius.all(Radius.circular(10.r))),
        focusedBorder: OutlineInputBorder(
            borderSide: BorderSide(color: Colors.white, width: 2.r),
            borderRadius: BorderRadius.all(Radius.circular(10.r)))),
  );
}
